package com.dg11185.nearshop.net.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.dg11185.libs.utils.print.PrintUtils;
import com.dg11185.nearshop.net.entity.Area;

/**
 * @author : daibo
 * @version : 2014-5-15 下午9:34:47
 * @see :
 */
public class GetAreaListResponse {

    public String responseStr;
    public String statusStr;
    
    public NetStatus status = null;
    
    public List<Area> areas = null;

    public GetAreaListResponse() {

        areas = new ArrayList<Area>();
    }

    public void parseJson(String response) {
        PrintUtils.printo(response);
        responseStr = response;
        try {
            JSONObject jsonObject = new JSONObject(response);
            status = NetStatus.getStatus(jsonObject.optString("status"));
            statusStr = jsonObject.getString("status");

            if(!jsonObject.isNull("areaList")){
                JSONArray areaArray = jsonObject.optJSONArray("areaList");
                for (int a = 0; a < areaArray.length(); a++) {
                    Area area = new Area();
                    area.parseEntity(areaArray.getJSONObject(a));
                    areas.add(area);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
